<?php

namespace app\api\controller;
//导入基类
use app\common\model\Coupon;
use app\common\model\Notice;
use app\common\model\Reward;
use app\common\model\UserCoupon as user_couponModel;
use app\common\model\User;
use app\common\model\Goods;
use think\Controller;
use think\facade\Cache;
use think\Db;
use app\common\model\Banner;
use app\common\model\Goods as goodsModel;
use think\Request;
use Endroid\QrCode\QrCode;
use app\common\model\IntegralLog as integralLoglModel;
use app\common\model\WalletLog as walletLoglModel;
use app\common\model\GoodsCategory as GoodsCategoryModel;
class Index extends Controller
{
    public function normal(){
        header("location:".$_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['SERVER_NAME'].'/mobile/travel/html/index.html');
    }
    public function index(){
       //echo  session('openid').session('userid');exit;
        $userid = session('userid');
        $userid = 10;
        //轮播图
        $banner= Banner::order('sort desc')->select();
        //商品分类
        $good_cat = GoodsCategoryModel::where('is_show',1)->field('cat_id,thumb,cat_name')->order('sort_order desc')->limit(4)->select();
        //优惠券
        $coupon = Coupon::where('status',0)->where('number','>',0)->where('expired_time','>',time())->order('id desc')->limit(2)->select();
        //print_r($coupon);exit;
        foreach($coupon as $key=>$value){
            if($value['cat_id'] == 2){
                $coupon[$key]['is_manjian'] = 1;
            }else{
                $coupon[$key]['is_manjian'] = 0;
            }
            $count = user_couponModel::where(['userid'=>$userid,'coupon_id'=>$value['id']])->count();
            if($count){
                $coupon[$key]['lingqu_status'] = 1;
            }else{
                $coupon[$key]['lingqu_status'] = 0;
            }
        }
        //限时秒杀
        $limitedtime_good = Goods::where(['is_home'=>1,'is_on'=>1,'cat_id'=>12])->where('end_time','>',time())->where('amount','>',0)->field('id,cat_id,name,price_spike,img1,start_time,end_time,landmark')->order('sort desc')->find();
        if($limitedtime_good){
            $cat_name = GoodsCategoryModel::where('cat_id',$limitedtime_good['cat_id'])->value('cat_name');
            $img = explode(',',$limitedtime_good['img1']);
            $limitedtime_good['cat_name'] = $cat_name;
            $limitedtime_good['poster'] = $img[0];
            $limitedtime_good['str_start_time'] = date('Y.m.d',$limitedtime_good['start_time']);
            $limitedtime_good['str_end_time'] = date('Y.m.d',$limitedtime_good['end_time']);
            $limitedtime_good['remaining_time'] =$limitedtime_good['end_time']-time();
        }
        //拼团秒杀
        $fightgroup_good = Goods::where(['is_home'=>1,'is_on'=>1,'cat_id'=>11])->where('end_time','>',time())->where('amount','>',0)->field('id,cat_id,name,fighting_price,img1,start_time,end_time,landmark')->order('sort desc')->find();
        if($fightgroup_good) {
            $cat_name = GoodsCategoryModel::where('cat_id',$fightgroup_good['cat_id'])->value('cat_name');
            $img = explode(',',$fightgroup_good['img1']);
            $fightgroup_good['cat_name'] = $cat_name;
            $fightgroup_good['poster'] = $img[0];
            $fightgroup_good['str_start_time'] = date('Y.m.d', $fightgroup_good['start_time']);
            $fightgroup_good['str_end_time'] = date('Y.m.d', $fightgroup_good['end_time']);
            $fightgroup_good['remaining_time'] =$fightgroup_good['end_time']-time();
        }
        $info = [
        'banner' => $banner,
        'good_cat' => $good_cat,
        'coupon' => $coupon,
        'limitedtime_good' => $limitedtime_good,
        'fightgroup_good' => $fightgroup_good,
        ];
        $data  = [
            'code'=>0,
            'msg'=>'请求成功',
            'info'=>$info,
        ];
        return json($data);

    }
    //旅游攻略
    public  function raiders(){
        $info = Notice::where('id',1)->find();
        $data  = [
            'code'=>0,
            'msg'=>'请求成功',
            'info'=>$info,
        ];
        return json($data);
    }
    //客服电话
    public function customser_phone(){
        $info = Reward::where('group',3)->value('condition');
        $data  = [
            'code'=>0,
            'msg'=>'请求成功',
            'info'=>$info,
        ];
        return json($data);
    }
}